package com.shsxt.controller;

import java.io.IOException;
import java.text.ParseException;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shsxt.controller.base.ControlBase;
import com.shsxt.model.Activity;
import com.shsxt.model.AuntMessageQuery;
import com.shsxt.model.BOrder;
import com.shsxt.model.COrder;
import com.shsxt.model.Coupon;
import com.shsxt.model.CustomerQuery;
import com.shsxt.model.DOrder;
import com.shsxt.model.JOrder;
import com.shsxt.model.KOrder;
import com.shsxt.model.Location;
import com.shsxt.model.Lunbo;
import com.shsxt.model.Notified;
import com.shsxt.model.ROrder;
import com.shsxt.model.ROrder2;
import com.shsxt.model.SOrder;
import com.shsxt.model.ServicePersonal;
import com.shsxt.model.UserFeedQuery;
import com.shsxt.model.UserInfo;
import com.shsxt.model.UserMessageQuery;
import com.shsxt.model.Userinfologin;
import com.shsxt.model.YOrder;
import com.shsxt.service.UserService;
import com.shsxt.vo.CdkeyQuery;
import com.shsxt.vo.TongjiQuery;
import com.shsxt.vo.WithdrawQuery;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;


@Controller//表示此类是控制器
@RequestMapping("demo01")
public class UserControl extends ControlBase{

	@Autowired
	private UserService userService;
	
	 //登录
	@RequestMapping("islogin.do")
	public String islogin(String name,String pwd){
		Userinfologin u=userService.islogin(name, pwd);
		if(u!=null)
		{
			request.getSession().setAttribute("u", u);
			return "main";
		}else
		{
			return "login";
		}
	}
	
	@RequestMapping("indexlxc")
	public String index(Integer state) {
		if (state == 1) {
			return "r_order";
		}else if(state==2){
			return "s_order";
		}else if(state==3){
			return "k_order";
		}else if(state==4){
			return "j_order";
		}else if(state==5){
			return "d_order";
		}else if(state==6){
			return "c_order";
		}else if(state==7){
			return "z_order";
		}else if(state==8){
			return "y_order";
		}else if(state==9){
			return "b_order";
		}
		return "cus_dev_plan";
	}
	
	@RequestMapping("customer")
	public String customer(Integer state) {
		if (state == 1) {
			return "user_message";
		}else if(state==2){
			return "aunt_message";
		}else if(state==3){
			return "user_feedback";
		}else if(state==4){
			return "aunt_feedback";
		}else if(state==5){
			return "withdraw";
		}else if(state==6){
			return "tongji";
		}else if(state==7){
			return "cdkey";
		}else if(state==8){
			return "coupon";
		}else if(state==9){
			return "cdkeySend";
		}else if(state==10){
			return "notified";
		}else if(state==11){
			return "activity";
		}else if(state==12){
			return "lunbo";
		}else if(state==13){
			return "location";
		}
		
		
		return null;
	}
	 //添加用户
	
	@RequestMapping("radd")
	public @ResponseBody Map<String, Object> radd(ROrder rorder,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.rupdatelxc(rorder);
			return result;
		}else{
			Map<String, Object> result = userService.add(rorder);
			return result;
		}
		
	}@RequestMapping("sadd")
	public @ResponseBody Map<String, Object> sadd(SOrder sorder,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.supdatelxc(sorder);
			return result;
		}	return null;
		
	}@RequestMapping("kadd")
	public @ResponseBody Map<String, Object> kadd(KOrder korder,Integer tag) {
		System.err.println(korder);
		if(tag==1){
			Map<String, Object> result = userService.kupdatelxc(korder);
			return result;
		}	return null;
		
	}@RequestMapping("jadd")
	public @ResponseBody Map<String, Object> jadd(JOrder jorder,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.jupdatelxc(jorder);
			return result;
		}	return null;
		
	}@RequestMapping("dadd")
	public @ResponseBody Map<String, Object> dadd(DOrder dorder,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.dupdatelxc(dorder);
			return result;
		}	return null;
	}
	@RequestMapping("cadd")
	public @ResponseBody Map<String, Object> cadd(COrder corder,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.cupdatelxc(corder);
			return result;
		}
		return null;
		
	}
	@RequestMapping("zadd")
	public @ResponseBody Map<String, Object> zcadd(ROrder2 rorder,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.zupdatelxc(rorder);
			return result;
		}
		return null;
		
	}
	@RequestMapping("yadd")
	public @ResponseBody Map<String, Object> ycadd(YOrder yorder,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.yupdatelxc(yorder);
			return result;
		}
		return null;
		
	}
	@RequestMapping("badd")
	public @ResponseBody Map<String, Object> bcadd(BOrder border,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.bupdatelxc(border);
			return result;
		}
		return null;
		
	}
	@RequestMapping("user_message_add")
	public @ResponseBody Map<String, Object> user_message_add(UserInfo user,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.user_message_add(user);
			return result;
		}
		return null;
		
	}
	@RequestMapping("aunt_message_add")
	public @ResponseBody Map<String, Object> aunt_message_add(ServicePersonal user,Integer tag) {
		if(tag==1){
			//修改阿姨
			Map<String, Object> result = userService.aunt_message_add(user);
			return result;
		}else if(tag==0){
			//添加阿姨
			Map<String, Object> result = userService.auntAdd(user);
			return result;
		}
		return null;
		
	}
	@RequestMapping("withadd")
	public @ResponseBody Map<String, Object> withadd(WithdrawQuery user,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.withadd(user);
			return result;
		}
		return null;
		
	}
	@RequestMapping("tongjiadd")
	public @ResponseBody Map<String, Object> tongjiadd(TongjiQuery user,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.tongjiadd(user);
			return result;
		}
		return null;
		
	}
	@RequestMapping("cdkeyadd")
	public @ResponseBody Map<String, Object> cdkeyadd(CdkeyQuery user,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.cdkeyadd(user);
			return result;
		}
		return null;
		
	}
	
	@RequestMapping("couponadd")
	public @ResponseBody Map<String, Object> couponadd(Coupon coupon,Integer tag) {
		if(tag==1){
			Map<String, Object> result = userService.couponadd(coupon);
			return result;
		}
		return null;
		
	}
	@RequestMapping("cdkeySendadd")
	public @ResponseBody Map<String, Object> cdkeySendadd(CdkeyQuery cdkey,Integer tag) {
		if(tag==1){
			System.err.println("tag==1");
			Map<String, Object> result = userService.cdkeySendadd(cdkey);
			return result;
		}
		return null;
		
	}
	@RequestMapping("couponSendadd")
	public @ResponseBody Map<String, Object> couponSendadd(Coupon coupon,Integer tag) {

		if(tag==2){
			Map<String, Object> result = userService.couponSendadd(coupon);
			return result;
		}
		return null;
		
	}
	@RequestMapping("notifiedadd")
	public @ResponseBody Map<String, Object> notifiedadd(Notified notified,Integer tag) throws APIConnectionException, APIRequestException {
		System.err.println(notified);

		if(tag==1){
			Map<String, Object> result = userService.notifiedadd(notified);
			return result;
		}else if(tag==0){
			Map<String, Object> result = userService.createNotifiedadd(notified);
			return result;
		}
		return null;
		
	}
	@RequestMapping("activityadd")
	public @ResponseBody Map<String, Object> activityadd(Activity activity,Integer tag) throws APIConnectionException, APIRequestException {
		System.err.println("XXX"+activity);

		if(tag==1){
			System.err.println("XXX"+activity);
			Map<String, Object> result = userService.activityadd(activity);
			return result;
		}
		return null;
		
	}
	@RequestMapping("lunboadd")
	public @ResponseBody Map<String, Object> lunboadd(Lunbo lunbo,Integer tag) throws APIConnectionException, APIRequestException {
		if(tag==1){
			Map<String, Object> result = userService.lunboadd(lunbo);
			return result;
		}
		return null;
		
	}
	
	//删除订单
	@RequestMapping("deletelxc")
	public @ResponseBody Map<String, Object> delete(String orderNumber) {
		System.err.println("id=="+orderNumber);
		Map<String, Object> result = userService.deletelxc(orderNumber);
		return result;
	}
	//删除通知
	@RequestMapping("deleteNotified")
	public @ResponseBody Map<String, Object> deleteNotified(String id) {
		System.err.println("id=="+id);
		Map<String, Object> result = userService.deleteNotified(id);
		return result;
	}
	//删除兑换码
		@RequestMapping("deleteCdkey")
		public @ResponseBody Map<String, Object> deleteCdkey(String cdkey) {
			Map<String, Object> result = userService.deleteCdkey(cdkey);
			return result;
		}
//删除优惠券
		@RequestMapping("deleteCoupon")
		public @ResponseBody Map<String, Object> deleteCoupon(String redeemCode) {
			Map<String, Object> result = userService.deleteCoupon(redeemCode);
			return result;
		}
//删除归属地
		@RequestMapping("deleteLocation")
		public @ResponseBody Map<String, Object> deleteLocation(String location) {
			Map<String, Object> result = userService.deleteLocation(location);
			return result;
		}
//删除提现
		@RequestMapping("deleteWithdraw")
		public @ResponseBody Map<String, Object> deleteWithdraw(String id) {
			Map<String, Object> result = userService.deleteWithdraw(id);
			return result;
		}
//删除统计
		@RequestMapping("deleteTongji")
		public @ResponseBody Map<String, Object> deleteTongji(String id) {
			Map<String, Object> result = userService.deleteTongji(id);
			return result;
		}
//删除轮播图
		@RequestMapping("deleteLunbo")
		public @ResponseBody Map<String, Object> deleteLunbo(String lunbo,HttpSession session) throws IOException {
			Map<String, Object> result = userService.deleteLunbo(lunbo,session);
			return result;
		}
//删除轮播图
		@RequestMapping("deleteActivity")
		public @ResponseBody Map<String, Object> deleteActivity(String id,HttpSession session) throws IOException {
			Map<String, Object> result = userService.deleteActivity(id,session);
			return result;
		}
//修改上班状态
		@RequestMapping("updateStage")
		public @ResponseBody Map<String, Object> updateStage(String phoneNumber) {
			Map<String, Object> result = userService.updateStage(phoneNumber);
			return result;
		}
		//修改转账状态
		@RequestMapping("openWithdraw")
		public @ResponseBody Map<String, Object> openWithdraw(String id) throws APIConnectionException, APIRequestException {
			Map<String, Object> result = userService.openWithdraw(id);
			return result;
		}
	 // 查询所有的用户
	@RequestMapping("/query")
	public String query(CustomerQuery query){
		return "test";
	}
	
	@RequestMapping("test")
	public @ResponseBody Map<String, Object> testselectForPage(CustomerQuery saleChanceQuery,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(saleChanceQuery,state);
		return result;
	}
	@RequestMapping("userPage")
	public @ResponseBody Map<String, Object> testselectForPage(UserMessageQuery userMessageQuery,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(userMessageQuery,state);
		return result;
	}
	@RequestMapping("auntPage")
	public @ResponseBody Map<String, Object> testselectForPage(AuntMessageQuery userMessageQuery,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(userMessageQuery,state);
		return result;
	}
	@RequestMapping("ufeedPage")
	public @ResponseBody Map<String, Object> testselectForPage(UserFeedQuery userMessageQuery,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(userMessageQuery,state);
		return result;
	}
	@RequestMapping("withPage")
	public @ResponseBody Map<String, Object> testselectForPage(WithdrawQuery withdrawQuery,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(withdrawQuery,state);
		return result;
	}
	@RequestMapping("tongjiPage")
	public @ResponseBody Map<String, Object> testselectForPage(TongjiQuery tongjiQuery,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(tongjiQuery,state);
		return result;
	}
	@RequestMapping("cdkeyPage")
	public @ResponseBody Map<String, Object> testselectForPage(CdkeyQuery tongjiQuery,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(tongjiQuery,state);
		return result;
	}
	@RequestMapping("couponPage")
	public @ResponseBody Map<String, Object> testselectForPage(Coupon coupon,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(coupon,state);
		return result;
	}
	@RequestMapping("notifiedPage")
	public @ResponseBody Map<String, Object> testselectForPage(Notified notified,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(notified,state);
		return result;
	}
	@RequestMapping("activityPage")
	public @ResponseBody Map<String, Object> testselectForPage(Activity activity,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(activity,state);
		return result;
	}
	@RequestMapping("lunboPage")
	public @ResponseBody Map<String, Object> testselectForPage(Lunbo lunbo,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(lunbo,state);
		return result;
	}
	@RequestMapping("locationPage")
	public @ResponseBody Map<String, Object> testselectForPage(Location location,String state) throws ParseException {
		Map<String, Object> result = userService.testselectForPage(location,state);
		return result;
	}
	

	
	
	
	
	
}
